package cn.intotw.rdcj.flash.fallback;
import cn.intotw.rdcj.core.bean.CommonErrors;
import cn.intotw.rdcj.core.bean.Result;
import cn.intotw.rdcj.flash.api.RdcjFlashApi;
import cn.intotw.rdcj.flash.dto.OrderCreateReqDto;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RdcjFlashFallbackFactory implements FallbackFactory<RdcjFlashApi> {
    private static Result exceptionCaught(Throwable throwable){
        return new Result(CommonErrors.SERVICE_UNAVAILABLE.getCode(), "fallback cause = " + throwable.getMessage());
    }
    @Override
    public RdcjFlashApi create(Throwable throwable) {
        return new RdcjFlashApi() {
            @Override
            public Result<OrderCreateReqDto> createOrder(Long userId) {
                return exceptionCaught(throwable);
            }
        };
    }
}